/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2015-02-10 11:06:09
 * @filename : static/component/promptTip/promptTip.js
 * @version : 
 * @description : 
 */

(function($){

    var promptTipTip = function() {
 
        this.checkEnv = function(opt) {
            //尽量使用CSS来做到响应式,需要JS修正的,在这里进行
            if (opt.dom) {
                opt.dom.html('');
            }
        };

        this.show = function(opt) {
            //检测环境变换,调整相应参数
            window.scroll(0,0);
            this.checkEnv(opt);
            switch(opt.type) {
               
               case 'success':
                   this.success(opt);
               break;
               
               case 'error':
                   this.error(opt);
               break;

               case 'btn':
                   this.btn(opt);
               break;

               case 'noData':
                   this.noData(opt);
               break;
			   
			   case 'noPermission':
                   this.noPermission(opt);
               break;

            }

        };     

        this.hide = function(opt) {
            switch(opt.type) {
               case 'noData':
                   this.noDataRemove(opt);
               break;
            }

        };

        this.noDataRemove = function(opt) {
            opt.dom.find('.noData').remove();
        };

        this.noData = function(opt) {
             var tthis = this, width = opt.dom.width(),
                 html = '<div class="noData"><div class="noDataIcon"></div><p class="noDataText">'+opt.text+'</p></div>';
             html = $(html).css('min-width',width+'px');
             opt.dom.append(html); 
        };
		
		this.noPermission = function(opt) {
             var tthis = this, width = opt.dom.width(),
                 html = '<div class="noPermission"><div class="noPermissionIcon"></div><div class="noPermissionText"><h3>Premium Service</h3><p>'+opt.text+'</p><span class="btn btn-noPermissionMore upgrade">Learn More</span></div></div>';
             html = $(html).css('min-width',width+'px');
             opt.dom.append(html); 
			 html.on('touchstart touchmove touchend',function(e){
                  e.stopPropagation(); 
                  e.preventDefault(); 
             });

             html.find('.upgrade').bind('touchend',function(e){
                   window.location.href='#upgrade/whole'; 
                   tthis.close(opt);  
             });
        };

        this.success = function(opt) {
             var tthis = this,
                 html = '<div class="success"> <span class="promptTip_left"></span> <span class="promptTip_content"> '+opt.text+'</span> <span class="promptTip_right"> X </span> </div>';
            
             html = $(html);

             $(html).find('.promptTip_right').on('tap',function(){
                 html.remove();                 
             });

             opt.dom.append(html); 

             if (opt.time) {
                 setTimeout(function(){
                     html.remove();
                 },opt.time);
             }
             //return html;
        };

        this.error = function(opt) {
             var tthis = this,
                 html =  '<div class="error"> <span class="promptTip_left"></span> <span class="promptTip_content"> '+opt.text+' </span> <span class="promptTip_right"> X </span> </div>';

             html = $(html);

             $(html).find('.promptTip_right').on('tap',function(){
                 html.remove();                 
             });

             opt.dom.append(html); 

             if (opt.time) {
                 setTimeout(function(){
                     html.remove();
                 },opt.time);
             }
             //return html;
        };

        this.btn = function(opt) {
             var tthis = this,
                 html = '<div class="pbtn"> <span class="promptTip_content"> '+opt.text+' </span> <span class="promptTip_btn"> '+opt.btnText+' </span> </div>';

             html = $(html);

             $(html).find('.promptTip_btn').on('tap',function(){
                 opt.callback();       
             });

             opt.dom.append(html);    
             
             if (opt.time) {
                 setTimeout(function(){
                     html.remove();
                 },opt.time);
             }

         
             //return html;
        };

   };

   var promptTipTipObj = new promptTipTip(),
       promptTipTipFun = promptTipTip;

   if (typeof define === "function" ) {
        define(function(require, exports, module) {
           //exports.promptTipTipObj = promptTipTipObj;         
           //exports.promptTipTipFun = promptTipTipFun; 
           module.exports = promptTipTipObj;  
        });
        /*
        define("promptTipTip/promptTipTip.js", [], function () { 
              return $.dialog;
        });
        */
   }



})($);
